home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 17018 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  5.2 KB

  1. Path: ix.netcom.com!news
  2. From: giuliano@ix.netcom.com(Giuliano Carlini)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Why don't you use garbage collection
  5. Date: 12 Apr 1996 18:11:03 GMT
  6. Organization: Netcom
  7. Message-ID: <4km6bn$mpe@dfw-ixnews3.ix.netcom.com>
  8. References: <4kiai0$mjd@dfw-ixnews8.ix.netcom.com> <316D291F.465D@sto.fdata.se>
  9. NNTP-Posting-Host: lbx-ca5-03.ix.netcom.com
  10. X-NETCOM-Date: Fri Apr 12  1:11:03 PM CDT 1996
  11.  
  12. In <316D291F.465D@sto.fdata.se> Niklas Mellin
  13. <niklas.mellin@sto.fdata.se> writes: 
  14. >Giuliano Carlini wrote:
  15. >>         - Why don't most C/C++ programmers use it?
  16. >I don't use it mostly because I tend to put almost every object I use
  17. >on the stack and not on the heap. The heap usage I hide in low level
  18. >classes, that typically have some kind of reference counter, and takes
  19. >care of the deletions.
  20. But reference counting doesn't collect cycles, is very inefficient, and
  21. imposes constraints which can't always be met; for example, deriving
  22. form a particular base class and always using a smart pointers.
  23.  
  24. >Sometimes it is necessary to put a high level object on the heap, but
  25. >those cases are so rare that it is not worth the trouble implementing
  26. >a garbage collector.
  27. I would think most large C++ programs use the heap a ton. Perhaps I'm
  28. wrong. Implementing a GC yourself would be impracticle for many, but
  29. there are at least two general purpose GC libraries. The first is
  30. freeware available at ftp://parcftp.xerox.com/pub/gc. The second is a
  31. commercial product from geodesic systems, www.geodesic.com. Both are
  32. excellent. Disclosure: I'm associated with geodesic, and hope to profit
  33. from my relationship through licensing fees/royalties.
  34.  
  35. >And personally I usually don't have any problem 
  36. >remembering the delete or delete[] in those cases.
  37. It seems to be a common problem among the programmers I meet.
  38.  
  39. >I am not against it, it is just that I think the stack suits my needs
  40. >better.
  41. The stack and static globals are certainly my first choice.
  42.  
  43. >I agree though that there have been cases I have wished I had
  44. >a garbage collector. But I don't think a garbage collector fits into
  45. >the language as well as in Smalltalk or Lisp.
  46. GC does not require any changes to the language. While it doesn't seem
  47. to fiFrom: giuliano@ix.netcom.com(Giuliano Carlini)
  48. Newsgroups: comp.lang.c++
  49. Subject: Re: Why don't you use garbage collection
  50. References: <4kiai0$mjd@dfw-ixnews8.ix.netcom.com> <316D291F.465D@sto.fdata.se>
  51.  
  52. In <316D291F.465D@sto.fdata.se> Niklas Mellin
  53. <niklas.mellin@sto.fdata.se> writes: 
  54. >Giuliano Carlini wrote:
  55. >>         - Why don't most C/C++ programmers use it?
  56. >I don't use it mostly because I tend to put almost every object I use
  57. >on the stack and not on the heap. The heap usage I hide in low level
  58. >classes, that typically have some kind of reference counter, and takes
  59. >care of the deletions.
  60. But reference counting doesn't collect cycles, is very inefficient, and
  61. imposes constraints which can't always be met; for example, deriving
  62. form a particular base class and always using a smart pointers.
  63.  
  64. >Sometimes it is necessary to put a high level object on the heap, but
  65. >those cases are so rare that it is not worth the trouble implementing
  66. >a garbage collector.
  67. I would think most large C++ programs use the heap a ton. Perhaps I'm
  68. wrong. Implementing a GC yourself would be impracticle for many, but
  69. there are at least two general purpose GC libraries. The first is
  70. freeware available at ftp://parcftp.xerox.com/pub/gc. The second is a
  71. commercial product from geodesic systems, www.geodesic.com. Both are
  72. excellent. Disclosure: I'm associated with geodesic, and hope to profit
  73. from my relationship through licensing fees/royalties.
  74.  
  75. >And personally I usually don't have any problem 
  76. >remembering the delete or delete[] in those cases.
  77. It seems to be a common problem among the programmers I meet.
  78.  
  79. >I am not against it, it is just that I think the stack suits my needs
  80. >better.
  81. The stack and static globals are certainly my first choice.
  82.  
  83. >I agree though that there have been cases I have wished I had
  84. >a garbage collector. But I don't think a garbage collector fits into
  85. >the language as well as in Smalltalk or Lisp.
  86. GC does not require any changes to the language. While it doesn't seem
  87. to fimake it a bit easier to do
  88. so.
  89.  
  90. >So why not do as I do? Write low level template classes that takes
  91. care
  92. >of the book keeping, and reuse them,
  93. Because this is buggier than using a GC.
  94.  
  95. >and don't use the heap more than necessary,
  96. 100% agreement.
  97.  
  98. > usually it is easier and more efficient to use the stack.
  99. Hmmm, I guess we work with diffent types of programs. While it is
  100. definitly more efficient to use the stack, most large programs that I
  101. deal with must use the heap.
  102.  
  103. >> For anyone who may be wondering, I believe that we should use
  104. garbage
  105. >> collection because:
  106. >>         - It vastly decreases the number of bugs in programs which
  107. use
  108. >> it.
  109. >
  110. >It is easier to debug a reference counting class than to debug a
  111. garbage
  112. >collector.
  113. But once the GC is debugged, your done. Reference counting classes will
  114. require that you meet their constraints. When you don't boom. Which
  115. means that each time you write new code, you will probably spend time
  116. debugging where you violated the constraints.
  117.  
  118. Thanks Niklas for your response. It reinforces my suspicion that most
  119. people don't even know that GC for C++ is available.
  120.  
  121. g
  122.